home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-wos-src / vlink / elf64.h < prev    next >
C/C++ Source or Header  |  1999-01-01  |  6KB  |  158 lines

  1. /* $VER: vlink elf64.h V0.3b (25.04.98)
  2.  *
  3.  * This file is part of vlink, a portable linker for multiple
  4.  * object formats.
  5.  * Copyright (c) 1997-99  Frank Wille
  6.  *
  7.  * vlink is freeware and part of the portable and retargetable ANSI C
  8.  * compiler vbcc, copyright (c) 1995-99 by Volker Barthelmann.
  9.  * vlink may be freely redistributed as long as no modifications are
  10.  * made and nothing is charged for it. Non-commercial usage is allowed
  11.  * without any restrictions.
  12.  * EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
  13.  * SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
  14.  *
  15.  *
  16.  * v0.3b (25.04.98) phx
  17.  *       File created.
  18.  */
  19.  
  20.  
  21. #include "elfcommon.h"
  22.  
  23.  
  24. struct Elf64_Ehdr {
  25.   unsigned char    e_ident[EI_NIDENT];    /* ELF "magic number" */
  26.   unsigned char    e_type[2];          /* Identifies object file type */
  27.   unsigned char    e_machine[2];       /* Specifies required architecture */
  28.   unsigned char    e_version[4];       /* Identifies object file version */
  29.   unsigned char    e_entry[8];         /* Entry point virtual address */
  30.   unsigned char    e_phoff[8];         /* Program header table file offset */
  31.   unsigned char    e_shoff[8];         /* Section header table file offset */
  32.   unsigned char    e_flags[4];         /* Processor-specific flags */
  33.   unsigned char    e_ehsize[2];        /* ELF header size in bytes */
  34.   unsigned char    e_phentsize[2];     /* Program header table entry size */
  35.   unsigned char    e_phnum[2];         /* Program header table entry count */
  36.   unsigned char    e_shentsize[2];     /* Section header table entry size */
  37.   unsigned char    e_shnum[2];         /* Section header table entry count */
  38.   unsigned char    e_shstrndx[2];      /* Section header string table index */
  39. };
  40.  
  41. struct Elf64_Phdr {
  42.   unsigned char p_type[4];          /* Identifies program segment type */
  43.   unsigned char p_flags[4];         /* Segment flags */
  44.   unsigned char p_offset[8];        /* Segment file offset */
  45.   unsigned char p_vaddr[8];         /* Segment virtual address */
  46.   unsigned char p_paddr[8];         /* Segment physical address */
  47.   unsigned char p_filesz[8];        /* Segment size in file */
  48.   unsigned char p_memsz[8];         /* Segment size in memory */
  49.   unsigned char p_align[8];         /* Segment alignment, file & memory */
  50. };
  51.  
  52. struct Elf64_Shdr {
  53.   unsigned char sh_name[4];         /* Section name, index in string tbl */
  54.   unsigned char sh_type[4];         /* Type of section */
  55.   unsigned char sh_flags[8];        /* Miscellaneous section attributes */
  56.   unsigned char sh_addr[8];         /* Section virtual addr at execution */
  57.   unsigned char sh_offset[8];       /* Section file offset */
  58.   unsigned char sh_size[8];         /* Size of section in bytes */
  59.   unsigned char sh_link[4];         /* Index of another section */
  60.   unsigned char sh_info[4];         /* Additional section information */
  61.   unsigned char sh_addralign[8];    /* Section alignment */
  62.   unsigned char sh_entsize[8];      /* Entry size if section holds table */
  63. };
  64.  
  65. struct Elf64_Sym {
  66.   unsigned char st_name[4];         /* Symbol name, index in string tbl */
  67.   unsigned char st_info[1];         /* Type and binding attributes */
  68.   unsigned char st_other[1];        /* No defined meaning, 0 */
  69.   unsigned char st_shndx[2];        /* Associated section index */
  70.   unsigned char st_value[8];        /* Value of the symbol */
  71.   unsigned char st_size[8];         /* Associated symbol size */
  72. };
  73. #define ELF64_ST_BIND(i) ((i)>>4)
  74. #define ELF64_ST_TYPE(i) ((i)&0xf)
  75. #define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
  76.  
  77. struct Elf64_Note {
  78.   unsigned char namesz[4];          /* Size of entry's owner string */
  79.   unsigned char descsz[4];          /* Size of the note descriptor */
  80.   unsigned char type[4];            /* Interpretation of the descriptor */
  81.   char          name[1];            /* Start of the name+desc data */
  82. };
  83.  
  84. struct Elf64_Rel {
  85.   unsigned char r_offset[8];    /* Location at which to apply the action */
  86.   unsigned char r_info[8];      /* index and type of relocation */
  87. };
  88.  
  89. struct Elf64_Rela {
  90.   unsigned char r_offset[8];    /* Location at which to apply the action */
  91.   unsigned char r_info[8];      /* index and type of relocation */
  92.   unsigned char r_addend[8];    /* Constant addend used to compute value */
  93. };
  94.  
  95. #define ELF64_R_SYM(i) ((i) >> 32)
  96. #define ELF64_R_TYPE(i)    ((i) & 0xffffffff)
  97. #define ELF64_R_INFO(sym,type) (((sym) << 32) + (type))
  98.  
  99. struct Elf64_Dyn {
  100.   unsigned char d_tag[8];           /* entry tag value */
  101.   union {
  102.     unsigned char d_val[8];
  103.     unsigned char d_ptr[8];
  104.   } d_un;
  105. };
  106.  
  107.  
  108. /* vlink specific - used to generate ELF64 output files */
  109.  
  110. #define ELF64_R_SYM_BE(ri) (read32(ri))
  111. #define ELF64_R_TYPE_BE(ri) (read32((ri)+4))
  112. #define ELF64_R_INFO_BE(ri,s,t) (write32((ri),(s)),write32((ri)+4,(t)))
  113. #define ELF64_R_SYM_LE(ri) (read32le((ri)+4))
  114. #define ELF64_R_TYPE_LE(ri) (read32le((ri))
  115. #define ELF64_R_INFO_LE(ri,s,t) (write32le((ri),(t)),write32le((ri)+4,(s)))
  116.  
  117. #define STRHTABSIZE 0x10000
  118. #define SHSTRHTABSIZE 0x100
  119.  
  120. struct StrTabNode {
  121.   struct node n;
  122.   struct StrTabNode *hashchain;
  123.   char *str;
  124.   uint32 index;
  125. };
  126.  
  127. struct StrTabList {
  128.   struct list l;
  129.   struct StrTabNode **hashtab;
  130.   unsigned long htabsize;
  131.   uint32 nextindex;
  132. };
  133.  
  134. struct SymbolNode {
  135.   struct node n;
  136.   struct SymbolNode *hashchain;
  137.   char *name;
  138.   struct Elf64_Sym s;
  139.   uint32 index;
  140. };
  141.  
  142. struct SymTabList {
  143.   struct list l;
  144.   struct SymbolNode **hashtab;
  145.   uint32 nextindex;
  146.   uint32 global_index;
  147. };
  148.  
  149. struct ShdrNode {
  150.   struct node n;
  151.   struct Elf64_Shdr s;
  152. };
  153.  
  154. struct RelaNode {
  155.   struct node n;
  156.   struct Elf64_Rela r;
  157. };
  158.